package com.cjie.controller;

import com.cjie.domain.ResponseResult;
import com.cjie.domain.entity.Article;
import com.cjie.service.ArticleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public List<Article> test(){
        return articleService.list();
    }

    /**
     * 查询热门文章列表
     * @return
     */
    @GetMapping("/hotArticleList")
    public ResponseResult<Article> hotArticleList(){
        return articleService.getHotArticleList();
    }


    /**
     * 分页查询博文列表
     * @param categoryId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult<Article> getArticleList(Long categoryId, Integer pageNum, Integer pageSize){
        return articleService.getArticleList(categoryId,pageNum,pageSize);
    }


    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }


}
